/*
Table_C01. Productivity and the PD ratio: Sentiment decomposition
Table_C02. Real GDP growth and productivity, news, and sentiment shocks
Table_C03. Productivity and the PD ratio
Table_C04. Real consumption growth and productivity, news, and sentiment shocks
Table_C05. Employment growth and productivity, news, and sentiment shocks
*/



* Table_C01. Productivity and the PD ratio: Sentiment decomposition
	clear all
	use "data/final_data_set.dta"
	xtset id year
	generate newid = id
	tsset newid year
	
	// full sample
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres zxb i.year, fe
				eststo
		}
		esttab using "Table_C01_a.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C01_a) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// G7 countries
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres zxb i.year if dum_G7 == 1, fe
				eststo
		}
		esttab using "Table_C01_b.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C01_b) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// Non-G7 countries
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres zxb i.year if dum_G7 == 0, fe
				eststo
		}
		esttab using "Table_C01_c.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C01_c) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear		

	/* Post-estimation tests: cross-sectional dependence
		qui: xi: xtreg f_rtfpna zres zxb i.year, robust fe cluster(id)
			predict r1, r
			xtcd2 r1 /// p-value = 0.000
		qui: xi: xtreg f_rtfpna zres zxb i.year if dum_G7 == 1, robust fe cluster(id)
			predict r2, r
			xtcd2 r2 /// p-value = 0.012
		qui: xi: xtreg f_rtfpna zres zxb i.year if dum_G7 == 0, robust fe cluster(id)
			predict r3, r
			xtcd2 r3 /// p-value = 0.000
		**** NOTE: similar results for two to four years ahead
	*/	

	
* Table_C02. Real GDP growth and productivity, news, and sentiment shocks
	clear all
	use "data/final_data_set.dta"
	xtset id year
	generate newid = id
	tsset newid year
	
	// full sample
		foreach x in f_g_rgdpna f2_g_rgdpna f3_g_rgdpna f4_g_rgdpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year, fe
				eststo
		}
		esttab using "Table_C02_a.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C02_a) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// G7 countries
		foreach x in f_g_rgdpna f2_g_rgdpna f3_g_rgdpna f4_g_rgdpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 1, fe
				eststo
		}
		esttab using "Table_C02_b.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C02_b) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// Non-G7 countries
		foreach x in f_g_rgdpna f2_g_rgdpna f3_g_rgdpna f4_g_rgdpna {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 0, fe
				eststo
		}
		esttab using "Table_C02_c.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C02_c) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
		
		
* Table_C03. Productivity and the PD ratio
	clear all
	use "data/final_data_set.dta"
	xtset id year

	// full sample
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: regxfe `x' zpd, robust fe(id year) cluster(id)
				eststo
		}
		esttab using "Table_C03_a.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C03) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2o)     ///
		drop()
		estimates clear
	// G7 countries
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: regxfe `x' zpd if dum_G7 == 1, robust fe(id year) cluster(id)
				eststo
		}
		esttab using "Table_C03_b.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C03) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2o)     ///
		drop()
		estimates clear
	// Non-G7 countries
		foreach x in f_rtfpna f2_rtfpna f3_rtfpna f4_rtfpna {
			qui: regxfe `x' zpd if dum_G7 == 0, robust fe(id year) cluster(id)
				eststo
		}
		esttab using "Table_C03_c.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C03) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2o)     ///
		drop()
		estimates clear

	
* Table_C04. Real consumption growth and productivity, news, and sentiment shocks
	clear all
	use "data/final_data_set.dta"
	xtset id year
	generate newid = id
	tsset newid year
	
	// full sample
		foreach x in f_g_rhc f2_g_rhc f3_g_rhc f4_g_rhc {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year, fe
				eststo
		}
		esttab using "Table_C04_a.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C04_a) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// G7 countries
		foreach x in f_g_rhc f2_g_rhc f3_g_rhc f4_g_rhc {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 1, fe
				eststo
		}
		esttab using "Table_C04_b.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C04_b) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// Non-G7 countries
		foreach x in f_g_rhc f2_g_rhc f3_g_rhc f4_g_rhc {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 0, fe
				eststo
		}
		esttab using "Table_C04_c.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C04_c) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear

		
* Table_C05. Employment growth and productivity, news, and sentiment shocks
	clear all
	use "data/final_data_set.dta"
	xtset id year
	generate newid = id
	tsset newid year

	// full sample
		foreach x in f_g_emp f2_g_emp f3_g_emp f4_g_emp {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year, fe
				eststo
		}
		esttab using "Table_C05_a.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C05_a) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// G7 countries
		foreach x in f_g_emp f2_g_emp f3_g_emp f4_g_emp {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 1, fe
				eststo
		}
		esttab using "Table_C05_b.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C05_b) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	// Non-G7 countries
		foreach x in f_g_emp f2_g_emp f3_g_emp f4_g_emp {
			qui: bootstrap, rep(200) seed(123) cluster(id) idcluster(newid) nodots nowarn: xtreg `x' zres_prod zres_econ zres_sent i.year if dum_G7 == 0, fe
				eststo
		}
		esttab using "Table_C05_c.rtf", replace cells(b(star fmt(%9.4f)) t(fmt(%9.2f))) style(fixed) title(Table_C05_c) ///
		t starlevels(* .10 ** .05 *** .01) b(4) scalars(r2)     ///
		drop()
		estimates clear
	
	
